﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Ccit.Utils;
using Ccit.ClassLibrary;

namespace Ccit.UserControls
{
    public partial class sys_range_frame : Ccit.Utils.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                _hidOrganId.Value = (null != Request.QueryString["organid"]) ? Request.QueryString["organid"].ToString() : "";
                if (_hidOrganId.Value == "")
                {
                    MsLoginUser oLoginUser = (MsLoginUser)Session["LogUserInfo"];
                    _hidOrganId.Value = oLoginUser.organId;
                    oLoginUser = null;
                }
                /* 9: 范围选择 0:用户选择 1:部门选择 2:职位选择 3:级别选择 */
                _hidSelType.Value = (null != Request.QueryString["seltype"]) ? Request.QueryString["seltype"].ToString() : "0";
                /* 页面中用于存放范围类型的控件ID */
                _hidCtrlRangeType.Value = (null != Request.QueryString["ctrltype"]) ? Request.QueryString["ctrltype"].ToString() : "";
                /* 页面中用于存放范围Id的控件ID */
                _hidCtrlRangeId.Value = (null != Request.QueryString["ctrlid"]) ? Request.QueryString["ctrlid"].ToString() : "";
                /* 页面中用于存放范围名称的控件ID */
                _hidCtrlRangeName.Value = (null != Request.QueryString["ctrlname"]) ? Request.QueryString["ctrlname"].ToString() : "";
                /* 范围名称分隔符 0: 空格 1: 换行*/
                _hidSeparator.Value = (null != Request.QueryString["sep"]) ? Request.QueryString["sep"].ToString() : "0";
                /* 嵌入选择页面的方式 0: 弹出式 1: overflow */
                _hidInsetType.Value = (null != Request.QueryString["insettype"]) ? Request.QueryString["insettype"].ToString() : "0";
                /* 回调主页面方法 */
                _hidCallMethod.Value = (null != Request.QueryString["callMethod"]) ? Request.QueryString["callMethod"].ToString() : "";

                initializePage();
            }
        }

        private void initializePage()
        {
            /* 根据选择类型设置标题 */
            string[] sTitleArray = getTitleBySelType();
            PageTitle.Text = sTitleArray[0];
            lbTitle.Text = sTitleArray[1];

            /* 设置范围类型 */
            if (_hidSelType.Value != "9")
            {
                tblRangeType.Visible = false;
                _hidRangeType.Value = _hidSelType.Value;
            }
            else
            {
                tblRangeType.Visible = true;                
            }
        }

        private string[] getTitleBySelType()
        {
            string[] sTitleArray = new string[2];
            switch (_hidSelType.Value)
            {
                case "9":
                    sTitleArray[0] = "范围选择页面";
                    sTitleArray[1] = "范围选择";
                    break;
                case "0":
                    sTitleArray[0] = "用户选择页面";
                    sTitleArray[1] = "用户选择";
                    break;
                case "1":
                    sTitleArray[0] = "部门选择页面";
                    sTitleArray[1] = "部门选择";
                    break;
                case "2":
                    sTitleArray[0] = "职位选择页面";
                    sTitleArray[1] = "职位选择";
                    break;
                case "3":
                    sTitleArray[0] = "级别选择页面";
                    sTitleArray[1] = "级别选择";
                    break;
            }

            return sTitleArray;
        }
    }
}
